package com.koron.css2.projectCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.mapper.PubReceiptMapper;
import com.koron.css2.projectCenter.bean.PjConsultBean;
import com.koron.css2.projectCenter.bean.query.PjConsultQueryBean;
import com.koron.css2.projectCenter.mapper.PjConsultMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.css2.workflow.WorkflowImpl;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

public class PjConsultRecovery implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		MessageBean<?> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", List.class);
		// TODO Auto-generated method stub
		PjConsultQueryBean queryBean = JsonUtils.objectToPojo(req.getData(), PjConsultQueryBean.class);
		//读取对应水司的流程平台应用密钥
		PubReceiptMapper mapper = factory.getMapper(PubReceiptMapper.class);
		PjConsultMapper pmapper = factory.getMapper(PjConsultMapper.class);
		PjConsultBean bean = pmapper.selectById(queryBean.getId());
		String setCode = mapper.getWorkflowApp(userInfo.getCurWaterCode());
		String processCode = "pj_consult";
		try {
			info = WorkflowImpl.recovery(setCode, processCode, bean.getProcessInstanceId());
			if(info.getCode()== Constant.MESSAGE_INT_SUCCESS) {
				pmapper.updateProcess(bean.getId(), "charge-approval");
			}
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription(e.getMessage());
			logger.error(e.getMessage(), e);
		}
		return info;
	}

}
